import { computed } from "vue"
import { OrderType } from "@/assets/js/filterTypes/OrderType"
import { GoodsType } from "@/assets/js/filterTypes/GoodsType"
import { MerchantType } from "@/assets/js/filterTypes/MerchantType"
import { WechatApplyType } from "@/assets/js/filterTypes/WechatApplyType"


//获取订单状态
export const formatOrderType = computed(() => {
	return (type: string | number) => {
		return OrderType[type] ? OrderType[type] : '未知'
	}
})
//通过订单状态获取状态文字颜色
export const getTypeColorByOrderType = computed(() => {
	return (type: number) => {
		if ([4, 5, 6, 7].includes(type)) {
			return 'error'
		} else if ([0, 3, 8].includes(type)) {
			return 'warning'
		} else {
			return
		}
	}
})


//获取项目（商品）状态
export const formatGoodsType = computed(() => {
	return (type: string | number) => {
		return GoodsType[type] ? GoodsType[type] : '未知'
	}
})
//通过项目（商品）状态获取状态文字颜色
export const getTypeColorByGoodsType = computed(() => {
	return (type: number) => {
		if ([3, 8].includes(type)) {
			return 'warning'
		} else {
			return 'gray8'
			return
		}
	}
})


//获取商家状态
export const formatMerchantType = computed(() => {
	return (type: string | number) => {
		return MerchantType[type] ? MerchantType[type] : '未知'
	}
})
//通过商家店铺状态获取状态文字颜色
export const getTypeColorByMerchantType = computed(() => {
	return (type: number) => {
		if ([1, 4].includes(type)) {
			return 'error'
		} else if ([2].includes(type)) {
			return 'warning'
		} else {
			return
		}
	}
})

//通过商家店铺状态获取状态图标背景色
export const getTypeIconBgColorByMerchantType = computed(() => {
	return (type: number) => {
		if ([1, 4].includes(type)) {
			return 'bg-error'
		} else if ([2].includes(type)) {
			return 'bg-warning'
		} else {
			return 'bg-success'
		}
	}
})


//获取微信商户申请状态
export const formartWechatStatus = computed(() => {
	return (type: string | number) => {
		return WechatApplyType[type] ? WechatApplyType[type] : '未知'
	}
})


//获取OSS文件缩放图片地址
export const getCosZoomImg = (param: { url: string, width: number | string, height: number | string, quality?: number, type?: string }) => {
	if (param.url?.substring(0, 4) == 'blob') {
		return param.url
	} else {
		if (param.type && param.type == 'video') {
			return `${param.url}?ci-process=snapshot&time=1&width${param.width}&height=${param.height}&=format=jpg`
		} else {
			return `${param.url}?imageMogr2/crop/${param.width}x${param.height}/gravity/center`
		}
	}
}

